package org.ixgua.website.config;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Author jyj
 * @Date 2020/4/23
 **/
@Configuration
@Slf4j
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
       log.info("swagger config ");
        return (new Docket(DocumentationType.SWAGGER_2)).apiInfo(apiInfo()).select().
                apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()).build();
    }


    private ApiInfo apiInfo() {
        String url ="http://www.ico.com.cn";
        String email ="lzh@ico.com.cn";
        Contact contact = new Contact("廖中辉",url,email);

        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("更多Spring Boot相关文章请关注")
                .termsOfServiceUrl("http://www.ico.com.cn")
                .contact(contact)
                .version("1.0")
                .build();
    }
}
